//
// Created by czm on 2023/12/12.
//

#ifndef CODE_COUNTER_RFIDSCANNER_H
#define CODE_COUNTER_RFIDSCANNER_H

#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "SerialPort.h"
#include <string>

#include "../global.h"

class RfidScanner {
public:
    RfidScanner();
    virtual ~RfidScanner();
    [[noreturn]] static void code_receive_task(void *arg);
private:
    /**
     * 发送开始扫描指令
     */
    void sendStart();
    /**
     * 处理串口接收
     * @param pPort
     * @return 卡号
     */
    void procReceive();

    void setBeepOn(bool on);
    void setPowerLevel(uint8_t level);

    static uint16_t calcCrc(uint8_t* buf,int len);
    static void fillCrc(uint8_t* buf, int len);
    void parseResponse(uint8_t* buf, int dataLen);

    SerialPort *m_pPort;
    uint8_t m_ant_index;
    int64_t m_last_send_time;
};


#endif //CODE_COUNTER_RFIDSCANNER_H
